package com.unittec.drainage.provider.manage.controller;

import com.alibaba.fastjson.JSON;
import com.unittec.drainage.provider.log.Log;
import com.unittec.drainage.provider.manage.service.HomePageService;
import com.unittec.drainage.provider.utils.ValidationUtils;
import com.unittec.drainage.sdk.manage.request.*;
import com.unittec.drainage.sdk.manage.response.*;
import com.unittec.drainage.sdk.manage.vo.RegionTreeVo;
import com.unittec.drainage.sdk.root.domain.GatewayRequest;
import com.unittec.drainage.sdk.root.domain.Result;
import com.unittec.drainage.sdk.root.enums.BizCode;
import com.unittec.drainage.sdk.root.enums.BizCodeEnum;
import com.unittec.drainage.sdk.root.enums.ErrorEnum;
import com.unittec.drainage.sdk.root.internal.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页管理
 *
 * @author wangyongfeng
 * @date 2021/9/1
 */
@RestController
@Api(tags = "首页管理")
public class HomePageController {
    
    @Autowired
    private HomePageService homePageService;

    @Autowired
    private Log log;

    @RequestMapping(value = "/301200", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "8个数据统计", notes = "8个数据统计")
    public Result<Res301200> getEightSum(@RequestBody GatewayRequest<Req301200> req) {
        log.debug(req, "getEightSum  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301200 res301200 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getEightSum(req.getContent());
            res301200 = new Res301200();
            res301200.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getEightSum {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301200);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301201", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "本年水系水量统计", notes = "本年水系水量统计")
    public Result<Res301201> getWaterVolumeOfWaterSystem(@RequestBody GatewayRequest<Req301201> req) {
        log.debug(req, "getWaterVolumeOfWaterSystem  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301201 res301201 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getWaterVolumeOfWaterSystem(req.getContent());
            res301201 = new Res301201();
            res301201.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getWaterVolumeOfWaterSystem {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301201);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301202", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "本年各月用水量曲线", notes = "本年各月用水量曲线")
    public Result<Res301202> getWaterConsumptionCurve(@RequestBody GatewayRequest<Req301202> req) {
        log.debug(req, "getWaterConsumptionCurve  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301202 res301202 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getWaterConsumptionCurve(req.getContent());
            res301202 = new Res301202();
            res301202.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getWaterConsumptionCurve {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301202);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301203", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "本年排行", notes = "本年排行")
    public Result<Res301203> getAnnualRanking(@RequestBody GatewayRequest<Req301203> req) {
        log.debug(req, "getAnnualRanking  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301203 res301203 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getAnnualRanking(req.getContent());
            res301203 = new Res301203();
            res301203.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getAnnualRanking {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301203);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301204", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "本年各水系污水费占比", notes = "本年各水系污水费占比")
    public Result<Res301204> getProportionOfSewageChargesByRiver(@RequestBody GatewayRequest<Req301204> req) {
        log.debug(req, "getProportionOfSewageChargesByRiver  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301204 res301204 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getProportionOfSewageChargesByRiver(req.getContent());
            res301204 = new Res301204();
            res301204.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getProportionOfSewageChargesByRiver {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301204);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301205", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "本年各区域污水费占比", notes = "本年各区域污水费占比")
    public Result<Res301205> getProportionOfSewageChargesByRegion(@RequestBody GatewayRequest<Req301205> req) {
        log.debug(req, "getProportionOfSewageChargesByRegion  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301205 res301205 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getProportionOfSewageChargesByRegion(req.getContent());
            res301205 = new Res301205();
            res301205.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getProportionOfSewageChargesByRegion {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301205);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301206", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "年度用水性质占比", notes = "年度用水性质占比")
    public Result<Res301206> getProportionByNature(@RequestBody GatewayRequest<Req301206> req) {
        log.debug(req, "getProportionByNature  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301206 res301206 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getProportionByNature(req.getContent());
            res301206 = new Res301206();
            res301206.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getProportionByNature {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301206);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301207", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "年度社区用水量排行", notes = "年度社区用水量排行")
    public Result<Res301207> getWaterConsumptionByCommunity(@RequestBody GatewayRequest<Req301207> req) {
        log.debug(req, "getWaterConsumptionByCommunity  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301207 res301207 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getWaterConsumptionByCommunity(req.getContent());
            res301207 = new Res301207();
            res301207.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getWaterConsumptionByCommunity {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301207);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301208", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "年度水系污水费统计", notes = "年度水系污水费统计")
    public Result<Res301208> getYearProportionByWaterSystem(@RequestBody GatewayRequest<Req301208> req) {
        log.debug(req, "getYearProportionByWaterSystem  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301208 res301208 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getYearProportionByWaterSystem(req.getContent());
            res301208 = new Res301208();
            res301208.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getYearProportionByWaterSystem {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301208);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }

    @RequestMapping(value = "/301209", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "欠收污水费统计", notes = "欠收污水费统计")
    public Result<Res301209> getArrearsProportion(@RequestBody GatewayRequest<Req301209> req) {
        log.debug(req, "getArrearsProportion  {} ,param {}", "begin", JSON.toJSONString(req.getContent()));
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301209 res301209 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = homePageService.getArrearsProportion(req.getContent());
            res301209 = new Res301209();
            res301209.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            if (e instanceof BusinessException) {
                return Result.error(req, e.getMessage());
            } else {
                return Result.error(req, ErrorEnum.QUERY_ERROR.getErrorMessage());
            }
        }
        log.debug(req, "getArrearsProportion {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            return Result.success(req, res301209);
        } else {
            return Result.error(req, bizCodeEnum);
        }
    }
}
